package com.briup.day09;

/**
 * @author ThinkBook
 */
public class Test02_Init {
    //求二维数组次大值
    public static int getSecValue(int[][] arr) {
        int max = arr[0][0];
        int sec = arr[0][0];

        for(int i = 0; i < arr.length; i++) {
            for(int j = 0; j < arr[i].length; j++) {
                // arr[i][j] max sec
                if(arr[i][j] > max) {
                    //先备份次大值
                    sec = max;
                    //再记录最大值
                    max = arr[i][j];
                }else if(arr[i][j] > sec) {
                    sec = arr[i][j];
                }else {

                }
            }
        }

        return sec;
    }
    public static void outArray(int[][] arr) {
        //遍历二维数组
        for(int i = 0; i < arr.length; i++) {
            for(int j = 0; j < arr[i].length; j++) {
                System.out.print(arr[i][j] + "\t");
            }
            System.out.println();
        }
    }

    public static void main(String[] args) {
        int[][] arr = new int[][]{
                {1,2,3},
                {4,5},
                {6,7,8}
        };
        int s = getSecValue(arr);
        System.out.println(s);
    }
    public static void main02(String[] args) {
        int[][] arr = new int[][]{
                {1,2,3},
                {4,5},
                {6,7,8}
        };

        //遍历二维数组
        for(int i = 0; i < arr.length; i++) {
            for(int j = 0; j < arr[i].length; j++) {
                System.out.print(arr[i][j] + "\t");
            }
            System.out.println();
        }

    }
    public static void main01(String[] args) {
        //静态初始化
        //1.
        int[][] arr = new int[][]{
                {1,2,3},
                {4,5},
                {6,7,8}
        };
        //2.
        int[][] arr2 = {
                {1,2,3},
                {4,5},
                {6,7,8}
        };

        System.out.println(arr[0][1]);//2
        //System.out.println(arr[1][2]);//越界异常
        System.out.println(arr[2][2]);//8

        //遍历二维数组
        for(int i = 0; i < arr.length; i++) {
            for(int j = 0; j < arr[i].length; j++) {
                System.out.print(arr[i][j] + "\t");
            }
            System.out.println();
        }
    }
}
